﻿#include "PyFITKMaterialsViscoElasticSolids.h"
#include "FITKAcousticsMaterialsViscoElastic.h"
#include "FITKAcousticsPhysics.h"
#include "FITKAcousticsAbsMaterial.h"
#include "FITKAcousticsSpectraManager.h"

Acoustics::PyFITKMaterialsViscoElasticSolids::PyFITKMaterialsViscoElasticSolids(const QString & name) :
    Acoustics::PyFITKMaterialsBase(name)
{
}

bool Acoustics::PyFITKMaterialsViscoElasticSolids::setDensityPoissonRatio(double density, double poissonsRatio)
{
    if (!_material|| density < 0 || poissonsRatio < 0)return false;

    FITKAcousticsMaterialsViscoElastic *elastic = dynamic_cast<Acoustics::FITKAcousticsMaterialsViscoElastic*>(_material);
    if (!elastic)return false;

    elastic->setDensity(density);
    elastic->setPoissonsRatio(poissonsRatio);
    return true;
}


bool Acoustics::PyFITKMaterialsViscoElasticSolids::setSpectra(const QString & shearModulus, const QString & dampingSpectrum)
{
    if (!_material|| shearModulus==""|| dampingSpectrum=="")return false;
//获取频谱管理器
    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return false;
    Acoustics::FITKAcousticsSpectraManager* matMgr = phy->getFITKAcousticsSpectraManager();
    if (matMgr == nullptr) return false;

    FITKAcousticsMaterialsViscoElastic *elastic = dynamic_cast<Acoustics::FITKAcousticsMaterialsViscoElastic*>(_material);
    if (!elastic)return false;

    if (!matMgr->getDataObjectByName(shearModulus) || !matMgr->getDataObjectByName(dampingSpectrum))
        return false;

//类型判断？
    int ID1 = matMgr->getDataObjectByName(shearModulus)->getDataObjectID();
    elastic->setShearModulusSpectrumID(ID1);

//类型判断？
    int ID2 = matMgr->getDataObjectByName(dampingSpectrum)->getDataObjectID();
    elastic->setDampingSpectrumID(ID2);;

    return true;
}

bool Acoustics::PyFITKMaterialsViscoElasticSolids::createMaterial(const QString & name)
{
    if (name == "")return false;
    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return false;
    Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
    if (matMgr == nullptr) return false;
    if (matMgr->getDataByName(name))return false;

    FITKAcousticsMaterialsViscoElastic *elastic = new FITKAcousticsMaterialsViscoElastic();
    if (!elastic)return false;

    elastic->setDataObjectName(name);
    _material = elastic;
    matMgr->appendDataObj(_material);

    return true;
}
